import unittest
from 动态规划alg import MovingAverage

class TestMovingAverage(unittest.TestCase):
    def test_example(self):
        """测试示例用例"""
        ma = MovingAverage(3)
        self.assertEqual(ma.next(1), 1.0)
        self.assertEqual(ma.next(10), 5.5)
        self.assertAlmostEqual(ma.next(3), 4.66667, places=5)
        self.assertEqual(ma.next(5), 6.0)

    def test_single_size(self):
        """测试窗口大小为1的情况"""
        ma = MovingAverage(1)
        self.assertEqual(ma.next(5), 5.0)
        self.assertEqual(ma.next(10), 10.0)
        self.assertEqual(ma.next(-3), -3.0)

    def test_large_window(self):
        """测试大窗口的情况"""
        size = 1000
        ma = MovingAverage(size)
        values = [1] * size
        for i, val in enumerate(values, 1):
            expected = sum(values[:i]) / i
            self.assertEqual(ma.next(val), expected)
        # 添加一个新值，窗口已满
        self.assertEqual(ma.next(2), (sum(values[1:]) + 2) / size)

if __name__ == '__main__':
    unittest.main()    